﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace peonwar
{
    static class Tools
    {
        public static float Born(float min, float max, float value)
        {
            if (value > max)
                return max;
            if (value < min)
                return min;
            return value;
        }

        public static void BankManage(User user, int value)
        {
            //Afficher l'argent perdue/gagnée
            user.Bank += value;
            Color color;
            string opera;

            if (user.Type == PlayerType.Player)
            {
                if (value > 0)
                {
                    color = Color.LightGreen;
                    opera = "+";
                }
                else
                {
                    color = Color.DarkRed;
                    opera = "   ";
                }

                User.AdvertList.Add(new Advert(new Vector2(210 , 445), GameData.Font_Simple2, opera + (value).ToString(), 1f, new Vector2(1, 0), 1f, color, false, false));
            }

        }

        public static string ToMinute(int value)
        {
            int minute = value / 60;
            int second = value % 60;

            string min = "" + minute;
            if (minute < 10)
                min = "0" + minute;

            string sec = "" + second;
            if (second < 10)
                sec = "0" + second;

            return min + ":" + sec;
        }

        public static string ToHourMinute(int value)
        {
            int hours = value / 3600;

            string h = "" + hours;
            if (hours < 10)
                h = "0" + hours;

            return hours + ":" + ToMinute(value % 3600);
        }

        public static string RemoveZewo(string s)
        {
            string result = s;
            if (result != "")
            {
                while (result[0] == '0' && result.Length > 1)
                {
                    result = result.Substring(1, result.Length - 1);
                }
            }
            return result;
        }

        public static string GetCharacterName(Perso chara)
        {
            string name = "";
            switch (chara)
            {
                case Perso.Kruiser:
                    name = GameData.GameString[112]; break;
                case Perso.Frohman:
                    name = GameData.GameString[113]; break;
                case Perso.Rengar:
                    name = GameData.GameString[114]; break;
                case Perso.Frika:
                    name = GameData.GameString[115]; break;
                case Perso.Emelle:
                    name = GameData.GameString[116]; break;
                case Perso.Doktor:
                    name = GameData.GameString[117]; break;
                default:
                    name = ""; break;
            }
            return name;
        }

        public static Perso GetRandomCharacter()
        {
            int max = 1;
            int min = 0;
            int progress = SettingManager.CurrentProfil.Progress;
            if (progress > 2)
            {
                max++;
                min++;
            }
            if (progress > 3)
                max++;
            if (progress > 5)
                max++;
            if (progress > 8)
                max++;
            if (progress > 10)
                max++;
            if (progress > 11)
                max++;

            return (Perso)(new Random().Next(min, max));
        }
    }
}
